package com.fengycx.autoconfigure;

import com.fengycx.properties.GTPushProp;
import com.fengycx.templeate.GTPushTemplate;
import com.getui.push.v2.sdk.ApiHelper;
import com.getui.push.v2.sdk.GtApiConfiguration;
import com.getui.push.v2.sdk.api.PushApi;
import com.getui.push.v2.sdk.api.UserApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({GTPushProp.class})
public class GTPushAutoConfiguration {


    @Bean
    public GTPushTemplate gtPushTemplate(GTPushProp gtPushProp){
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        // 设置httpClient最大连接数，当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
//        System.setProperty("http.maxConnections", "200");

        apiConfiguration.setAppId(gtPushProp.getAppid());
        apiConfiguration.setMasterSecret(gtPushProp.getMasterSecret());
        apiConfiguration.setDomain(gtPushProp.getDomain());
        apiConfiguration.setAppKey(gtPushProp.getAppKey());
        apiConfiguration.setAnalyseStableDomainInterval(500);
        apiConfiguration.setCheckHealthInterval(500);
        apiConfiguration.setOpenAnalyseStableDomainSwitch(false);  //关闭

        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        PushApi pushApi = apiHelper.creatApi(PushApi.class);
        UserApi userApi = apiHelper.creatApi(UserApi.class);

        return new GTPushTemplate(gtPushProp,userApi,pushApi);
    }


}
